package ttu.takeshi.tasks.server;

import java.io.IOException;
import java.io.Serializable;

import ttu.eclass.server.Service;
import ttu.eclass.util.ClientConnector;
import ttu.eclass.util.DBConnector;
import ttu.takeshi.tasks.db.LoginQueryTask;

public class LoginTask extends AccountTask implements Serializable {

	private static final long serialVersionUID = 7641701988566797243L;
	private Service service;
	boolean isPass = false;

	@Override
	public void run() {
		DBConnector dbConnector = service.getDBConnector();
		ClientConnector clientConnector = service.getClientConnector();
		String username = user.getUsername();
		String password = user.getPassword();

		LoginQueryTask loginQueryTask = new LoginQueryTask(username);
		try {
			LoginQueryTask result = (LoginQueryTask) dbConnector
					.query(loginQueryTask);
			String cpassword = result.getPassword();
			isPass = cpassword.equals(password);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			clientConnector.sendObject(this);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	@Override
	void initService(Service service) {
		this.service = service;
	}

}
